Imports DocumentFormat.OpenXml.Spreadsheet
Imports FineUI
Imports Kimmo
Imports Microsoft.VisualBasic.CompilerServices
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlServerCe
Imports System.Diagnostics
Imports System.Runtime.CompilerServices

''' <summary>
''' This is the beginning of the Infrastructure_Type business object to handle interaction between the user interface and the database.
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Class clsInfrastructureType
    Public Property Id As Integer = 0
    Public Property TypeName As String = ""
    Public Property IsNew As Boolean = False
    Public Property DateFields As String = ""
    Public Property FieldsToUpdate As String = "Id,TypeName"

''' <summary>
''' The new method of the class to create new Infrastructure_Type records.
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Sub New()
    MyBase.New()
    Clear()
    IsNew = True
    DateFields = ""
    FieldsToUpdate = "Id,TypeName"
End Sub

''' <summary>
''' The Clear method clears all properties of the business object to defaults.
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Sub Clear()
    Id = 0
    TypeName = ""
End Sub

''' <summary>
''' Delete Infrastructure_Type records specified by a list of ID.
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
    Public Shared Sub Delete(ByRef Records As List(Of String))
        For Each rsStr As String In Records
            SQLCompact.RunQuery("delete from [Infrastructure_Type] where ID = " & rsStr, True)
        Next
    End Sub


''' <summary>
''' Delete Infrastructure_Type records meeting a particular field name criteria. In this case, Id
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Shared Sub DeleteById(ByVal intId As Integer)
    SQLCompact.RunQuery("Delete from [Infrastructure_Type] where [Id] = " & intId)
End Sub

''' <summary>
''' Delete Infrastructure_Type records from a list of particular field. In this case, Id
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Shared Sub DeleteByListOfId(ByRef Records As List(Of String))
        For Each intId As String In Records
    SQLCompact.RunQuery("Delete from [Infrastructure_Type] where [Id] = " & intId)
        Next
End Sub

''' <summary>
''' Delete Infrastructure_Type records meeting a particular field name criteria. In this case, TypeName
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Shared Sub DeleteByTypeName(ByVal strTypeName As String)
    SQLCompact.RunQuery("Delete from [Infrastructure_Type] where [TypeName] = '" & strTypeName & "'")
End Sub

''' <summary>
''' Delete Infrastructure_Type records from a list of particular field. In this case, TypeName
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Shared Sub DeleteByListOfTypeName(ByRef Records As List(Of String))
        For Each strTypeName As String In Records
    SQLCompact.RunQuery("Delete from [Infrastructure_Type] where [TypeName] = '" & strTypeName & "'")
        Next
End Sub

''' <summary>
''' Return a particular field based on another field. In this case return Infrastructure_Type.Id based on Infrastructure_Type.Id
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Shared Function IdById(ByVal intId As Integer) As Integer
    Dim mv As String = SQLCompact.RecordReadToMv("Infrastructure_Type", "Id", intId, "Id", ";", "Integer")
    mv = clsDL.MvField(mv, 1, ";")
    Return Val(mv)
End Function


''' <summary>
''' Return a particular field based on another field. In this case return Infrastructure_Type.Id based on Infrastructure_Type.TypeName
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Shared Function IdByTypeName(ByVal strTypeName As String) As Integer
    Dim mv As String = SQLCompact.RecordReadToMv("Infrastructure_Type", "TypeName", strTypeName, "Id", ";", "String")
    mv = clsDL.MvField(mv, 1, ";")
    Return Val(mv)
End Function


''' <summary>
''' Return a particular field based on another field. In this case return Infrastructure_Type.TypeName based on Infrastructure_Type.Id
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Shared Function TypeNameById(ByVal intId As Integer) As String
    Dim mv As String = SQLCompact.RecordReadToMv("Infrastructure_Type", "Id", intId, "TypeName", ";", "Integer")
    mv = clsDL.MvField(mv, 1, ";")
    Return mv
End Function


''' <summary>
''' Return a particular field based on another field. In this case return Infrastructure_Type.TypeName based on Infrastructure_Type.TypeName
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Shared Function TypeNameByTypeName(ByVal strTypeName As String) As String
    Dim mv As String = SQLCompact.RecordReadToMv("Infrastructure_Type", "TypeName", strTypeName, "TypeName", ";", "String")
    mv = clsDL.MvField(mv, 1, ";")
    Return mv
End Function


''' <summary>
''' Return the list of strings of a particular field. In this case Infrastructure_Type.Id
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
    Public Shared Function IdList(Optional bAddNone As Boolean = False, Optional bIsDate As Boolean = False, Optional FldDelim As String = ";") As List(Of String)
        Dim strs As List(Of String) = SQLCompact.TableDistinctList("Infrastructure_Type", "Id", "{0}", bAddNone, bIsDate, FldDelim)
        Return strs
    End Function

''' <summary>
''' Return the list of strings of a particular field. In this case Infrastructure_Type.TypeName
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
    Public Shared Function TypeNameList(Optional bAddNone As Boolean = False, Optional bIsDate As Boolean = False, Optional FldDelim As String = ";") As List(Of String)
        Dim strs As List(Of String) = SQLCompact.TableDistinctList("Infrastructure_Type", "TypeName", "{0}", bAddNone, bIsDate, FldDelim)
        Return strs
    End Function

''' <summary>
''' Return the total number of records in the table Infrastructure_Type
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Shared Function Count() As Integer
Dim nRecords As Integer = 0
Dim dt As DataTable = SQLCompact.OpenDataTable("select Count(ID) as Records from [Infrastructure_Type]")
For Each dr As DataRow In dt.Rows
nRecords = Val(dr("Records").ToString)
Next
Return nRecords
End Function


''' <summary>
''' Return the total number of records with a particular value in a field. In this case Infrastructure_Type.Id
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Shared Function CountById(ByVal intId As Integer) As Integer
Dim sQry As String = "Select Count(ID) As Records from [Infrastructure_Type] where [Id] = " & intId
Dim dt As DataTable = SQLCompact.OpenDataTable(sQRY)
Dim nRecords as integer = 0
For Each dr As DataRow In dt.Rows
nRecords = Val(dr("Records").ToString)
Next
Return nRecords
End Function

''' <summary>
''' Return the total number of records with a particular value in a field. In this case Infrastructure_Type.TypeName
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Shared Function CountByTypeName(ByVal strTypeName As String) As Integer
Dim sQry As String = "Select Count(ID) As Records from [Infrastructure_Type] where [TypeName] = '" & strTypeName & "'"
Dim dt As DataTable = SQLCompact.OpenDataTable(sQRY)
Dim nRecords as integer = 0
For Each dr As DataRow In dt.Rows
nRecords = Val(dr("Records").ToString)
Next
Return nRecords
End Function

''' <summary>
''' Return True or False if a particular Infrastructure_Type record exists.
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Shared Function Exists(ByVal intID as Integer) As Boolean
Dim flag As Boolean = SQLCompact.RecordExists("Infrastructure_Type", "ID", intID, "Long")
Return flag
End Function


''' <summary>
''' Return True or False if a particular Infrastructure_Type record exists based on Id
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Shared Function ExistsById(ByVal intId As Integer) As Boolean
Dim flag As Boolean = SQLCompact.RecordExists("Infrastructure_Type", "Id", intId, "Integer")
Return flag
End Function

''' <summary>
''' Return True or False if a particular Infrastructure_Type record exists based on TypeName
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Shared Function ExistsByTypeName(ByVal strTypeName As String) As Boolean
Dim flag As Boolean = SQLCompact.RecordExists("Infrastructure_Type", "TypeName", strTypeName, "String")
Return flag
End Function

''' <summary>
''' Read Method to read Infrastructure_Type record from the database using a primarykey.
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Sub Read(ByVal sID As String)
Try
Clear()
Dim nRead As New DataSet()
nRead = SQLCompact.RecordSeek("Infrastructure_Type", "ID", sID, "*", "Integer")
Dim xCount As Boolean = nRead.Tables(0).Rows.Count - 1 <> -1
If xCount Then
Dim xRow As DataRow = nRead.Tables(0).Rows(0)
Id = Val(xRow("Id").ToString)
TypeName = xRow("TypeName").ToString
Me.IsNew = False
nRead.Dispose()
End If
Catch exc as Exception
Throw new Exception(exc.Message)
End Try
End Sub

''' <summary>
''' Save a Infrastructure_Type record to the database using a primary key. This uses a property get and FieldsToUpdate, DateFields to update the database.
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Sub Save()
Try
Dim strTable As String = "Infrastructure_Type"
Dim strPriKey As String = "ID"
Dim CommText As String = ""
Dim xCommand As New SqlCeCommand
If ID = -1 Then
ID = SQLCompact.TableMaxValue(strTable, strPriKey, "") + 1
IsNew = True
Else
IsNew = False
End If
If FieldsToUpdate = "*" Then
FieldsToUpdate = SQLCompact.Table_FieldNames(strTable, False, ",")
End If
FieldsToUpdate = clsDL.MvRemoveDuplicates(Me.FieldsToUpdate, ",")
Dim strParameters As String = clsDL.MvPrefixBy(FieldsToUpdate, "@", ",")
If IsNew Then
CommText = clsDL.BuildInsertCommand(strTable, FieldsToUpdate, ",")
Else
CommText = clsDL.BuildUpdateCommand(strTable, FieldsToUpdate, strPriKey, ",")
End If
xCommand = SQLCompact.OpenCommand(CommText)
Dim spFields() As String = Split(FieldsToUpdate, ",")
With xCommand
.Parameters.Clear()
For each strField As String In spFields
Dim datePos As Integer = clsDL.MvSearch(DateFields, strField, ",")
If datePos > 0 Then
Dim strValue as string = clsDL.PropertyGet(Me, strField).ToString
.Parameters.AddWithValue("@" & strField, IIf((IsDate(strValue) = True), CDate(strValue), DBNull.Value))
Else
.Parameters.AddWithValue("@" & strField, clsDL.PropertyGet(Me, strField))
End If
Next
.ExecuteNonQuery()
End With
SQLCompact.Connection.Close()
xCommand.Dispose()
Catch exc as Exception
Throw new Exception(exc.Message)
End Try
End Sub

''' <summary>
''' This method builds up an editable grid based on selected records. The grid has Save, Clone and Delete buttons
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Shared Sub ShowInfrastructure_Type(ByRef grdViews As FineUI.Grid, ByVal strFilter As String)
clsFineUI.Grid.Clear(grdViews, "", "")
clsFineUI.Grid.TableName = "Infrastructure_Type"
clsFineUI.Grid.DataKeyNames = "Id"
clsFineUI.Grid.PageSize = 50
clsFineUI.Grid.AllowPaging = True
clsFineUI.Grid.AllowSorting = True
clsFineUI.Grid.LoadMask = False
clsFineUI.Grid.Title = "Infrastructure_Type"
clsFineUI.Grid.ShowBorder = False
clsFineUI.Grid.ShowHeader = False
clsFineUI.Grid.EnableRowNumber = False
clsFineUI.Grid.AutoHeight = True
clsFineUI.Grid.AutoPostBack = False
clsFineUI.Grid.EnableCheckBoxSelect = True
clsFineUI.Grid.AutoWidth = True
clsFineUI.Grid.EnableAlternateRowColor = True
clsFineUI.Grid.EnableCollapse = False
clsFineUI.Grid.EnableMouseOverColor = True
clsFineUI.Grid.EnableMultiSelect = True
clsFineUI.Grid.EnableViewState = True
clsFineUI.Grid.EnableAjax = True
clsFineUI.Grid.ColumnLines = True
clsFineUI.Grid.ToolTipField = "TypeName"
clsFineUI.Grid.IsDatabasePaging = False
clsFineUI.Grid.ShowGridHeader = True
clsFineUI.Grid.EnableHeaderMenu = True
clsFineUI.Grid.EnableColumnHide = True
clsFineUI.Grid.AddTextBox("Id", "Id", "{0}", "", "100", FineUi.TextAlign.Left, False, False, True)
clsFineUI.Grid.AddTextBox("TypeName", "Type Name", "{0}", "", "100", FineUi.TextAlign.Left, False, False, True)
clsFineUI.Grid.AddSave()
clsFineUI.Grid.AddClone()
clsFineUI.Grid.AddDelete()
If Len(strFilter) > 0 Then clsFineUI.Grid.Filter = strFilter
clsFineUI.Grid.OrderBy = "Id"
clsFineUI.Grid.BuildSelectCommand()
clsFineUI.Grid.UseSQLCompact = True
clsFineUI.Grid.Update(Nothing)
End Sub

''' <summary>
''' Builds a readonly grid based on selected records, this grid has Edit, Clone, Delete, Like and Comment buttons.
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Shared Sub ShowGrid(ByRef grdViews As FineUI.Grid, ByVal strFilter As String)
clsFineUI.Grid.Clear(grdViews, "", "")
clsFineUI.Grid.TableName = "Infrastructure_Type"
clsFineUI.Grid.DataKeyNames = "Id"
clsFineUI.Grid.PageSize = 50
clsFineUI.Grid.AllowPaging = True
clsFineUI.Grid.AllowSorting = True
clsFineUI.Grid.LoadMask = False
clsFineUI.Grid.Title = "Infrastructure_Type"
clsFineUI.Grid.ShowBorder = False
clsFineUI.Grid.ShowHeader = False
clsFineUI.Grid.EnableRowNumber = False
clsFineUI.Grid.AutoHeight = True
clsFineUI.Grid.AutoPostBack = False
clsFineUI.Grid.EnableCheckBoxSelect = True
clsFineUI.Grid.AutoWidth = True
clsFineUI.Grid.EnableAlternateRowColor = True
clsFineUI.Grid.EnableCollapse = False
clsFineUI.Grid.EnableMouseOverColor = True
clsFineUI.Grid.EnableMultiSelect = True
clsFineUI.Grid.EnableViewState = True
clsFineUI.Grid.EnableAjax = True
clsFineUI.Grid.ColumnLines = True
clsFineUI.Grid.ToolTipField = "TypeName"
clsFineUI.Grid.IsDatabasePaging = False
clsFineUI.Grid.ShowGridHeader = True
clsFineUI.Grid.EnableHeaderMenu = True
clsFineUI.Grid.EnableColumnHide = True
clsFineUI.Grid.AddColumn("Id", "Id", "{0}", "", "", False, "100", FineUi.TextAlign.Left, False)
clsFineUI.Grid.AddColumn("TypeName", "Type Name", "{0}", "", "", False, "100", FineUi.TextAlign.Left, False)
clsFineUI.Grid.AddEditCloneDelete()
clsFineUI.Grid.AddLikeComment()
If Len(strFilter) > 0 Then clsFineUI.Grid.Filter = strFilter
clsFineUI.Grid.OrderBy = "Id"
clsFineUI.Grid.BuildSelectCommand()
clsFineUI.Grid.UseSQLCompact = True
clsFineUI.Grid.Update(Nothing)
End Sub

''' <summary>
''' Import Infrastructure_Type records from a csv file.
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Shared Sub ImportFile(ByVal SourceFile As String, ByVal FileData As String)
Try
Dim spLines As String() = Strings.Split(FileData, vbCr & vbLf)
For each strLine As String In spLines
strLine = strLine.Trim
If Len(strLine) > 0 Then
Dim spLine As String() = Strings.Split(strLine, ",")
Dim clsNewInfrastructureType As New clsInfrastructureType
With clsNewInfrastructureType
.IsNew = True
.Id = -1
.Save
End With
End If
Next
Catch exc as exception
Throw new Exception(exc.message)
End Try
End Sub

''' <summary>
''' Define a blank Infrastructure_Type record and save it in a database. This method is useful for a grid like interface.
''' </summary>
''' <remarks>This code is automatically generated by SystemBuilder.Show.</remarks>
Public Sub Blank()
Dim clsNewInfrastructureType As New clsInfrastructureType
clsNewInfrastructureType.Clear()
clsNewInfrastructureType.IsNew = True
clsNewInfrastructureType.Id = -1
clsNewInfrastructureType.Save
clsNewInfrastructureType = Nothing
End Sub
End Class

